package com.ztsoft.user.controller.user;

import com.ztsoft.user.pojo.entity.user.SysMenu;
import com.ztsoft.user.pojo.vo.user.SysMenuVo;
import com.ztsoft.user.service.user.SysMenuService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/menu")
@CrossOrigin("*")
@Api(tags = "菜单控制层")
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;

    @GetMapping("/queryByPage")
    @ApiOperation(value = "查询菜单", notes = "带分页的条件查询")
    public Result<Object> queryByPage(SysMenu menu, Integer currentPage, Integer pageSize) {
        return sysMenuService.queryMenuByPage(menu, currentPage, pageSize);
    }

    @GetMapping("/queryTreeSelect")
    @ApiOperation(value = "查询树状菜单", notes = "树状结构的菜单")
    public Result<Object> queryTreeSelect() {
        return sysMenuService.queryMenuTreeSelect();
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加菜单", notes = "添加菜单")
    public Result<Object> add(@RequestBody SysMenuVo sysMenuVo) {
        return sysMenuService.addMenu(sysMenuVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新菜单", notes = "更新菜单")
    public Result<Object> updateUser(@RequestBody SysMenuVo sysMenuVo) {
        return sysMenuService.updateMenu(sysMenuVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除菜单", notes = "按照id删除菜单")
    public Result<Object> delete(@PathVariable("id") String id) {
        return sysMenuService.deleteMenu(id);
    }

}